<?php
class Admin_SiteInfoController extends Apps_Controller_Action_Admin {
    public function indexAction() {
        $this->_forward('read');
    }

	public function readAction() {
		$rq   = $this->_request;

    	$tbSiteInfo = new Model_DbTable_SiteInfo();
        $siteInfo = $tbSiteInfo->getSiteInfo()->query()->fetch();

        $form = new Admin_Form_AddSiteInfo();
        if($rq->isPost()) {
            if($form->isValid($rq->getParams())) {
                $data = $form->getValues();
                //$data['password_email_send_to_friend'] = rand(10000, 99999).'vct'.$form->getValue('password_email_send_to_friend').'@760211';
                if(!$siteInfo) {
                    $r = $tbSiteInfo->safelyInsert($data);
                } else {
                    $r = $tbSiteInfo->safelyUpdate($data, array('id =?' => $siteInfo['id']));
                }

                $this->_flashMessenger->addMessage(
                	$r
                    ? self::$msgAddSuccess
                    : self::$msgAddFailed);

                return $this->goToActionIndex();
            }
        } else {
            if($siteInfo) {
                $form->populate($siteInfo);
            }
        }

        $this->view->form = $form;
	}
}
